import { _decorator, Component, Node } from "cc";
const { ccclass, property } = _decorator;

@ccclass("UiBg")
export class UiBg extends Component {
  @property(Node)
  public bg01: Node = null!;
  @property(Node)
  public bg02: Node = null!;

  @property
  speed: number = 100;
  start() {}

  update(deltaTime: number) {
    let pos01 = this.bg01.position;
    let pos02 = this.bg02.position;
    this.bg01.setPosition(pos01.x, pos01.y - this.speed * deltaTime, pos01.z);
    this.bg02.setPosition(pos02.x, pos02.y - this.speed * deltaTime, pos02.z);

    let p1 = this.bg01.position;
    let p2 = this.bg02.position;
    if (this.bg01.position.y < -852) {
      this.bg01.setPosition(p2.x, p2.y + 852, p2.z);
    }
    if (this.bg02.position.y < -852) {
      this.bg02.setPosition(p1.x, p1.y + 852, p1.z);
    }
  }
}
